import Vue from "vue";
import VueRouter from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
//配置滚动条
NProgress.configure({ showSpinner: false, ease: "ease", speed: 3000 });
// import { component } from "vue/types/umd";

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login"),
    meta: {
      title: "登录 - 网抑云音乐"
    }
  },
  {
    path: "/",
    // name: "layout",
    component: () => import("@/views/layout"),
    redirect: "/discover",
    children: [
      {
        path: "/discover",
        name: "discover",
        component: () => import("@/views/discover/discover"),
        redirect: "/discover/recommended",
        children: [
          {
            path: "/discover/recommended",
            name: "recommended",
            component: () => import("@/views/discover/recommended/recommended"),
            meta: {
              title: "个性推荐 - 网抑云音乐",
              activeMenu: "/discover"
            }
          },
          {
            path: "/discover/playlist",
            name: "playlist",
            component: () => import("@/views/discover/playlist"),
            meta: {
              title: "歌单 - 网抑云音乐",
              activeMenu: "/discover"
            }
          },
          {
            path: "/discover/radiolist",
            name: "radiolist",
            component: () => import("@/views/discover/radio"),
            meta: {
              title: "主播电台 - 网抑云音乐",
              activeMenu: "/discover"
            }
          },

          {
            path: "/discover/ranklist",
            name: "ranklist",
            component: () => import("@/views/discover/rank"),
            meta: {
              title: "排行榜 - 网抑云音乐",
              activeMenu: "/discover"
            }
          },
          {
            path: "/discover/singerlist",
            name: "singerlist",
            component: () => import("@/views/discover/singer/singerlist"),
            meta: {
              title: "歌手 - 网抑云音乐",
              activeMenu: "/discover"
            }
          },
          {
            path: "/discover/newmusic",
            name: "newmusic",
            component: () => import("@/views/discover/newmusic"),
            redirect: "/discover/newmusic/musicCourier",
            meta: {
              title: "最新音乐 - 网抑云音乐",
              activeMenu: "/discover"
            },
            children: [
              {
                path: "/discover/newmusic/musicCourier",
                name: "musicCourier",
                component: () =>
                  import("@/views/discover/newmusic/components/newmusic"),
                meta: {
                  title: "最新音乐 - 音乐速递 - 网抑云音乐",
                  activeMenu: "/discover",
                  activeNewmusic: "newmusic"
                }
              },
              {
                path: "/discover/newmusic/newDisc",
                name: "newDisc",
                component: () =>
                  import("@/views/discover/newmusic/components/newalbum"),
                meta: {
                  title: "最新音乐 - 新碟上架 - 网抑云音乐",
                  activeMenu: "/discover",
                  activeNewmusic: "newmusic"
                }
              }
            ]
          }
        ],
        meta: {
          title: "发现音乐 - 网抑云音乐",
          activeMenu: ""
        }
      },
      {
        path: "/playlistdetails",
        name: "playlistdetails",
        component: () => import("@/views/details/playlistdetails"),
        meta: {
          title: "歌单详情 - 网抑云音乐",
          activeMenu: ""
        }
      },
      {
        path: "/singerdetails",
        name: "singerdetails",
        component: () => import("@/views/details/singerdetails"),
        meta: {
          title: "歌手详情 - 网抑云音乐",
          activeMenu: ""
        }
      },
      {
        path: "/albumdetails",
        name: "albumdetails",
        component: () => import("@/views/details/albumdetails"),
        meta: {
          title: "专辑详情 - 网抑云音乐",
          activeMenu: ""
        }
      },
      {
        path: "/musicdetails",
        name: "musicdetails",
        component: () => import("@/views/details/musicdetails"),
        meta: {
          title: "单曲详情 - 网抑云音乐",
          activeMenu: ""
        }
      },
      {
        path: "/video",
        name: "video",
        component: () => import("@/views/video"),
        redirect: "/video/mvlist",
        children: [
          {
            path: "/video/videolist",
            name: "videolist",
            component: () => import("@/views/video/videolist"),
            meta: {
              title: "视频 - 网抑云音乐",
              activeMenu: "/video"
            }
          },
          {
            path: "/video/mvlist",
            name: "mvlist",
            component: () => import("@/views/video/mvlist"),
            meta: {
              title: "MV - 网抑云音乐",
              activeMenu: "/video"
            }
          }
        ],
        meta: {
          title: "视频 - 网抑云音乐",
          activeMenu: "/video"
        }
      },
      {
        path: "videodetails",
        name: "videodetails",
        component: () => import("@/views/details/videoDetails"),
        meta: {
          title: "视频详情 - 网抑云音乐",
          activeMenu: "/video"
        }
      },
      {
        path: "mvdetails",
        name: "mvdetails",
        component: () => import("@/views/details/mvDetails"),
        meta: {
          title: "MV详情 - 网抑云音乐",
          activeMenu: "/video"
        }
      },
      {
        path: "/search",
        name: "search",
        component: () => import("@/views/search/search"),
        meta: {
          title: "搜索 - 网抑云音乐"
        }
      }
    ]
  }
];

const router = new VueRouter({
  routes
});
// 路由变化时
router.beforeEach((to, from, next) => {
  //进度条开始
  NProgress.start();
  next();
});
//后置路由守卫
router.afterEach(() => {
  //关闭进度条
  NProgress.done();
});
export default router;
